const React = require('react');
const HeaderNav = require('./HeaderNav');
const Head = require('./Head');
const cn = require('classnames');
const fs = require('fs');

// Component used to provide same head, header, footer, other scripts to all pages
class Site extends React.Component {
    render() {
        const { page, children } = this.props;
        const { current, config } = page;
        const isExist = config.footer && fs.existsSync(process.cwd() + '/' + config.footer);
        const Footer = isExist && require(process.cwd() + '/' + config.footer);
        const hasToc = !!current.tocList;

        return (
            <html>
                <Head page={page} />
                <body className={cn("sideNavVisible", { separateOnPageNav: hasToc })} >
                    <HeaderNav page={page} />
                    <div className="navPusher">
                        {children}
                        {
                            Footer && <Footer config={config} /> || (
                                config.footer &&
                                <footer className="nav-footer" id="footer">
                                    <section className="copyright">
                                        {config.footer}
                                    </section>
                                </footer>
                            )
                        }
                    </div>
                </body>
            </html>
        );
    }
}
module.exports = Site;
